package com.econ.powercloud.ems.service.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.econ.powercloud.ems.dal.entity.EmsYkYtRecord;
import com.econ.powercloud.ems.dal.mapper.EmsYkYtRecordMapper;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author : zjf
 * @Description :遥控遥调最后一次下发设置值记录DAO层
 * @Date : 2022/1/10 8:58
 * @Modified by : zjf
 */
@Repository
public class EmsYkYtRecordDAO extends ServiceImpl<EmsYkYtRecordMapper, EmsYkYtRecord> {

    /**
     * 根据deviceCodes查询历史设定值
     */
    public List<EmsYkYtRecord> getListByDeviceCodes(List<String> deviceCodes){
        LambdaQueryWrapper<EmsYkYtRecord> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.in(EmsYkYtRecord::getDeviceCode,deviceCodes);
        return this.baseMapper.selectList(lambdaQueryWrapper);
    }

    public void deleteRecord(String deviceCode,Integer remoteType,String dit){
        EmsYkYtRecord emsYkYtRecord = EmsYkYtRecord.builder().deviceCode(deviceCode).dit(dit).remoteType(remoteType).build();
        QueryWrapper<EmsYkYtRecord> wrapper = new QueryWrapper<>(emsYkYtRecord);
        this.baseMapper.delete(wrapper);
    }

    public void updateBatchByDitAndDeviceCode(List<EmsYkYtRecord> updateList) {
        this.baseMapper.updateBatchByDitAndDeviceCode(updateList);
    }
}
